All Questions
15 questions
4votes
2answers
131views
Find largest sum not involving consecutive values
There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
4votes
5answers
823views
Find maximum value of recursively-defined "fusc" function
I've been trying this question from SPOJ, which asks for the user to enter a number n, and they will receive a maximum fusc value that lies in between 0 to ...
1vote
1answer
239views
Target Sum array using Dynamic Programming
I'm learning Dynamic Programming and trying to solve this Target Sum array problem. I've to find an array of integers that sums to a given target sum using the integers of given input array. I've used ...
3votes
1answer
3kviews
Recursive solution of ordered Coin Combinations II (CSES)
Question Link Consider a money system consisting of n coins. Each coin has a positive integer value. Your task is to calculate the number of distinct ordered ways you can produce a money sum x using ...
0votes
3answers
480views
Calculate sum of a substring
I try to solve some old Codeforces questions. The problem is; Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q ...
3votes
0answers
135views
C++ - Longest Common Subsequence
Link to the Problem Here is my code to compute the length of the longest common subsequence of two integer arrays arr[] and brr[]...
1vote
2answers
247views
Recursive brute-force approach to maximum points you can obtain from cards
I came across this question on Leetcode. The question description is as follows: There are several cards arranged in a row, and each card has an associated number of points. The points are given in ...
3votes
3answers
344views
SPOJ Emoticon challenge
I tried this spoj problem and solved it using Dynamic Programming, but I was getting Time Limit Exceeded. The challenge is to count the number of occurrences of the subsequence "KEK" in each input ...
3votes
1answer
929views
SPOJ - Alphacode, using dynamic programming
I am currently trying out a programming problem, SPOJ Alphacode, that involves dynamic programming. In an encoding system where A=1, B=2, …, Z=26, a message 25114 ...
5votes
1answer
1kviews
Hackerrank "Bricks Game"
Problem URL This is the solution I came up with the minimax problem stated above. I did a top-down recursive approach with memoization, and I think this should be \$O(n)\$, since we are filling out a ...
1vote
3answers
1kviews
Code for calculating best possible combination in an array
The problem here , requires me to find the best possible combination of values in an array which is nearest to 0 and are adjacent to each other , here is an little excerpt from it, The government of ...
7votes
2answers
5kviews
Obtaining a target number only using the operations ×2, ×3, and +1
Problem Introduction You are given a primitive calculator that can perform the following three operations with the current number x: multiply x by 2, multiply x by 3, or add 1 to x. Your goal ...
4votes
3answers
13kviews
Calculating the sum of array elements to the left and right
I am using C++ to code the following logic: An Array is given we have to traverse the array such that sum of array elements to its left must be equal to sum of elements to its right. BTW this is ...
4votes
1answer
946views
Optimizing a dynamic programming solution for "Oil Well"
I'm trying to solve the Oil Well problem on Hackerrank using dynamic programming and it works. However, it times out for some of the test cases. I wanted to know how this program can be improved so ...
5votes
2answers
5kviews
Optimizing O(m n) solution for longest common subsequence challenge
Given two strings string X of length x1 and string Y of length ...